/**
 * AggregationNetworkManager.java
 * ************************** 
 * @date Mar 31, 2011
 * @author Michele Tamburini
 * 
 * **************************
 */
package gossipServices.aggregation;

import gossipServices.gossipMessages.AggregationMessage;
import gossipServices.network.GeneralServicesMessageDispatcher;

import java.util.logging.Level;
import java.util.logging.Logger;

import networkRmi.NetworkManager;

/**
 * Description: 
 * The AggregationNetworkManager provides the handler
 * function to extract the messages of the Aggregation
 * protocol from the incoming queue messages.
 * It extends the GeneralServicesNetManager and
 * take advantage of the base class functions of 
 * send and receive. 
 * Please be very careful to the value of 
 * ACTIVE_THREAD_MAXIMUM_WAIT: it defines the maximum
 * time in msec that the active thread 
 * waits an answer from a process q after a call to
 *   msg = receive(q);
 * 
 *
 */
public class AggregationNetworkManager extends GeneralServicesMessageDispatcher {
	
	/**
	 * Define the maximum time in msec that the active thread
	 * waits for an answer from the process q after a call to
	 *   msg = receive(q);
	 * Putting to 0 this value results in a blocking 
	 * call and may lead to a distributed deadlock.
	 * It is strongly suggested to set it at least 
	 *    >= 2*cycleLenght
	 * If this time is too short may lead to a overload
	 * of messages sent by the active thread that are kept 
	 * in the NetworkManager queue and may lead to a corrupted 
	 * estimation value. 
	 */
	public static int ACTIVE_THREAD_MAXIMUM_WAIT = 10000;
		
	Logger log = Logger.getLogger("AGGNetMan");
	
	public AggregationNetworkManager(NetworkManager nm){
		super(nm, AggregationMessage.class, AggPassiveThread.class, AggActiveThread.class);
		log.setLevel(Level.OFF);
//		disableNetManErrors();
		
		/*
		 * The following instruction make the call
		 *   Message m = receive(NodeDescriptor node);
		 * blocking;
		 */
		nonBlockingReceiveWaitTime = ACTIVE_THREAD_MAXIMUM_WAIT; 
	}


}
